package com.github.wxpay.sdk;

import java.io.ByteArrayInputStream;
import java.io.InputStream;

/**
 * Created by spoplar on 18-2-5.
 */
public class WxPayConfigImpl extends WXPayConfig {

    private byte[] certData;

    private String appid;

    private String mchid;

    private  String appkey;


    private static WxPayConfigImpl INSTANCE;

    public WxPayConfigImpl() throws Exception {
//        String certPath = "/home/spoplar/certs/cert_dev/apiclient_cert.p12";
//        File file = new File(certPath);
//        InputStream in = new FileInputStream(file);
//        this.certData = new byte[ (int)file.length()];
//        in.read(this.certData);
//        in.close();
    }

    public WxPayConfigImpl(String appid, String mchid, String appkey) {
        this.appid = appid;
        this.mchid = mchid;
        this.appkey = appkey;
    }

        public static WxPayConfigImpl getInstance() throws Exception{
        if (INSTANCE == null) {
            synchronized (WxPayConfigImpl.class) {
                if (INSTANCE == null) {
                    INSTANCE = new WxPayConfigImpl();
                }
            }
        }
        return INSTANCE;
    }


    public void setAppid(String appid) {
        this.appid = appid;
    }

    public void setMchid(String mchid) {
        this.mchid = mchid;
    }

    public void setAppkey(String appkey) {
        this.appkey = appkey;
    }

    public String getAppID() {
        return this.appid;
    }

    public String getMchID() {
        return this.mchid;
    }

    public String getKey() {
        return this.appkey;
    }

    public InputStream getCertStream() {
        ByteArrayInputStream certBis;
        certBis = new ByteArrayInputStream(this.certData);
        return certBis;
    }


    public int getHttpConnectTimeoutMs() {
        return 2000;
    }

    public int getHttpReadTimeoutMs() {
        return 10000;
    }

    protected IWXPayDomain getWXPayDomain() {
        return WxPayDomainImpl.instance();
    }

    public String getPrimaryDomain() {
        return "api.mch.weixin.qq.com";
    }

    public String getAlternateDomain() {
        return "api2.mch.weixin.qq.com";
    }

    @Override
    public int getReportWorkerNum() {
        return 1;
    }

    @Override
    public int getReportBatchSize() {
        return 2;
    }


}
